<?php

/**
 * This is the model class for table "address".
 *
 * The followings are the available columns in table 'address':
 * @property integer $id
 * @property string $city
 * @property integer $userid
 * @property string $postal_code
 * @property string $phone
 * @property string $street
 * @property string $province
 * @property string $country_code
 *
 * The followings are the available model relations:
 * @property User $user
 */
class Address extends CommonActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Address the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'address';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('city, postal_code, phone, street, province, country_code', 'required'),
			array('userid', 'numerical', 'integerOnly'=>true),
			array('city, street', 'length', 'max'=>100),
			array('postal_code, country_code', 'length', 'max'=>10),
			array('phone', 'length', 'max'=>15),
			array('province', 'length', 'max'=>30),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, city, userid, postal_code, phone, street, province, country_code', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'user' => array(self::BELONGS_TO, 'User', 'userid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'city' => 'City',
			'userid' => 'Userid',
			'postal_code' => 'Postal Code',
			'phone' => 'Phone',
			'street' => 'Street',
			'province' => 'Province',
			'country_code' => 'Country Code',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('userid',$this->userid);
		$criteria->compare('postal_code',$this->postal_code,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('street',$this->street,true);
		$criteria->compare('province',$this->province,true);
		$criteria->compare('country_code',$this->country_code,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}